package org.zjt.log.exception;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * DESC
 *
 * @author
 * @create 2017-06-20 上午10:31
 **/
public class LogMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String pattern = "\\w+(E|e)xception:";
        Matcher matcher = Pattern.compile(pattern).matcher(value.toString());
        if (matcher.find()) {
            Text k = new Text(matcher.group().replace(":",""));
            IntWritable v = new IntWritable(1);
            context.write(k,v);
        }
    }
}
